
#include <gtest/gtest.h>

#include "nane/core/crt/crt.h"
#include "nane/core/log.h"

class LogTester
    : public nane::ILogger
{
public:
    void Log( const char* _message, const char* _file
            , const char* _line, const char* _function, nane::ELogMessageLevel::raw_type _messageLevel )
    {
        m_lastMessage.clear();
        m_lastMessage.append( nane::ELogMessageLevel::toString(nane::enum_cast<nane::ELogMessageLevel>(_messageLevel)) );
        m_lastMessage.append( ": " );
        m_lastMessage.append( _message );
    }

    const std::string& GetLastMessage() const { return m_lastMessage; }

private:
    std::string m_lastMessage;
};

TEST( NaneTest, LogCheck )
{
    EXPECT_TRUE( nane::InitializeCRT(false) );
    nane::LogManager::SetMessagesLevel( nane::ELogMessageLevel::Info );
    LogTester logTester;
    nane::LogManager::RegisterLogger( &logTester );
    LOG_ERROR( "Log message" );
    EXPECT_STREQ( "Error: Log message", logTester.GetLastMessage().c_str() );
    LOG_WARNING( "Log warning" );
    EXPECT_STREQ( "Warning: Log warning", logTester.GetLastMessage().c_str() );
    LOG_INFO( "Log info" );
    EXPECT_STREQ( "Info: Log info", logTester.GetLastMessage().c_str() );
    nane::ShutdownCRT();
}
